﻿using System;
using System.Xml;
using System.Text;

namespace BfLib.Web.RSS
{
    public class RSSChannelCloud
    {
        private string _domain;//domain="rpc.sys.com" port="80" path="/RPC2" registerProcedure="pingMe" protocol="soap"
        private int _port;
        private string _path;
        private string _registerProcedure;
        private string _protocol;

        #region Public accessors
        public int Port
        {
            get { return _port; }
        }

        public string Domain
        {
            get { return _domain; }
        }

        public string Path
        {
            get { return _path; }
        }

        public string RegisterProcedure
        {
            get { return _registerProcedure; }
        }


        public string Protocol
        {
            get { return _protocol; }
        }

        #endregion

        public RSSChannelCloud(XmlNode node)
        {
            if (node == null) return;

            if (node.Attributes["domain"] != null)
                this._domain = node.Attributes["domain"].Value;

            if (node.Attributes["port"] != null)
                this._port = StrToIntDef(node.Attributes["port"].Value, -1);

            if (node.Attributes["path"] != null)
                this._path = node.Attributes["path"].Value;

            if (node.Attributes["registerProcedure"] != null)
                this._registerProcedure = node.Attributes["registerProcedure"].Value;

            if (node.Attributes["protocol"] != null)
                this._protocol = node.Attributes["protocol"].Value;
        }

        private int StrToIntDef(string s, int def)
        {
            if (s == null)
                return def;

            int i = def;

            if (int.TryParse(s, out i))
            {
                return i;
            }
            else return def;


        }

    }


}
